package com.xlf.service.base.controller.admin;

import com.xlf.common.core.pojo.mode.AjaxResult;
import com.xlf.common.core.pojo.mode.BaseController;
import com.xlf.pojo.base.Announcement;
import com.xlf.pojo.base.Tag;
import com.xlf.service.base.service.AnnouncementService;
import com.xlf.service.base.service.TagService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author xlf 2734029211@qq.com
 * @Date 2023/12/31 11:18
 * @Description: TODO 公告管理
 * @Version 1.0
 */
@RestController
@RequestMapping("/base/admin/announcement")
public class AdminAnnouncementController extends BaseController {

    @Autowired
    AnnouncementService announcementService;

    @GetMapping("/list")
    @PreAuthorize("@ss.hasPermi('base:admin:announcement:list')")
    public AjaxResult list(Announcement announcement){
        startPage();
        return success(getDataTable(announcementService.getList(announcement)));
    }

    @PostMapping("/saveOrUpdate")
    @PreAuthorize("@ss.hasPermi('base:admin:announcement:saveOrUpdate')")
    public AjaxResult saveOrUpdate(@RequestBody Announcement announcement){
        return success(announcementService.saveOrUpdate(announcement));
    }


    @GetMapping("/query/{id}")
    @PreAuthorize("@ss.hasPermi('base:admin:announcement:query')")
    public AjaxResult query(@PathVariable(value = "id") String id){
        return success(announcementService.getById(id));
    }

    @DeleteMapping("/delete")
    @PreAuthorize("@ss.hasPermi('base:admin:announcement:delete')")
    public AjaxResult delete(@RequestBody List<String> ids){
        announcementService.removeBatchByIds(ids);
        return success("删除成功！");
    }

    @PutMapping("/disabled")
    @PreAuthorize("@ss.hasPermi('base:admin:announcement:saveOrUpdate')")
    public AjaxResult updateStatus(@RequestBody Announcement announcement){
        return success(announcementService.updateStatus(announcement));
    }


}
